import tf from 'then-fs'

async function getData() {
    const str1 = await tf.readFile('./10-data.json', 'utf8')
    return JSON.parse(str1)
}

async function updataData(obj) {
    try {
        const arr = await getData()
        const index = arr.findIndex(ele => obj.id == ele.id)
        arr.splice(index, 1, obj)
        tf.writeFile('./10-data.json', JSON.stringify(arr))
        return '修改成功'
    } catch (e) {
        console.log(e.message)
    }
}
updataData({
    "author": "吵sdsds吵",
    "bookname": "给对sds方",
    "publisher": "武汉出版社sdsd",
    "id": 5
}).then(res => {
    console.log(res);
})